fix: parse tool calls in streaming reasoning branch#177
fix: parse tool calls in streaming reasoning branch#177Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Conversation
When reasoning parsing is enabled, the streaming handler uses an if/else structure where the reasoning parser branch and tool parser branch are mutually exclusive. This means tool calls in streaming responses are never parsed when reasoning is enabled — they come through as raw XML text instead of structured tool_calls. Fix: Add tool call accumulation and parsing inside the reasoning parser branch, operating on delta_msg.content (the content portion after reasoning extraction). Handles all three tool parser outcomes: suppress (inside markup), emit structured tool_calls, or pass through content. Also fixes finish_reason to return "tool_calls" when tools were detected in the reasoning branch, matching the behavior of the standard path.
7b72f19 to
6680b18
Compare
|
Production evidence from M2 Ultra 128GB, Qwen3.5-122B-A10B, BatchedEngine with MTP routing and streaming: Without this fix, tool calls in the streaming reasoning branch are silently dropped. The reasoning parser consumes the The fix adds tool call parsing to the streaming reasoning branch so both reasoning content and tool calls are extracted correctly. Tested with OpenCode (multi-turn agent), Cline, and direct API calls with |
|
Status ping — this PR has been idle 8 days and was the one Thump604 PR skipped from the 2026-04-07 coordinated rollup. No known blockers on our side: branch is rebased against current main ( |
|
I rechecked this in light of the new official Gemma 4 chat templates. My read is the same: that template update does not obsolete this streaming parser fix. The template update changes how messages are rendered into the prompt. This PR is about streamed model output when reasoning blocks and tool calls appear together. Those are different layers of the stack. I also revalidated the live Gemma lane after the template sync: tool calling, tool-result replay, and plain reasoning split are all still green. So I would keep this PR in the queue as a real fix candidate, but it probably wants to be restacked with the newer raw-output-preservation work rather than evaluated in isolation against an older server state. |
|
Hey @Thump604 — this fix is now covered in This PR has merge conflicts with current |
|
Closing as superseded by #278. The merged reasoning-parser/tool-parser streaming pipeline on current main covers this path, and this branch now conflicts with the updated server changes. |
Fix streaming when both reasoning (thinking) tags and tool calls appear in the same response.
Before: reasoning parser consumed
<think>content but left artifacts that broke tool call parsing downstream.After: reasoning extraction runs first, cleaned text passed to tool parser.
Files:
server.pystreaming handlerTest: Send a request with tools enabled and a model that uses
<think>tags. Response should have bothreasoning_contentandtool_callspopulated correctly.